

#include "..\\Includes\\CPlayer.h"
#include "..\\Includes\\CAction.h"
#include "..\\Includes\\MikeUtils.h"
#include "..\\Includes\\CCamera.h"

CAction::CAction()
{
	m_bCanPerform   = true;
	m_bIsPerforming = false;

}

void CAction::AssignToPlayer(CPlayer *player)
{
	m_pPlayer = player;

}

CAction::~CAction()
{


}



CActionJump::CActionJump()
{
	m_bCanPerform   = true;
	m_bIsPerforming = false;


}


bool CActionJump::Perform(float param1, float param2, float param3, float param4)
{
	if(param1 > 0)
	{
		m_pPlayer->Jump(param1);
		m_bCanPerform = false;
		m_bIsPerforming = true;
	}
	else
	{
		MikeUtils::ASSERT(false, "No TimeScale has been passed as param1!!", __FILE__, __LINE__);
		return false;
	}


	return true;
}

void CActionJump::Complete()
{
	m_bCanPerform = true;
	m_bIsPerforming = false;

}




CActionSprint::CActionSprint()
{
	m_bCanPerform   = true;
	m_bIsPerforming = false;
	oldFOV = 0.0f;
	oldMaxVelXZ = 0.0f;

}


bool CActionSprint::Perform(float param1, float param2, float param3, float param4)
{
	if(m_pPlayer->GetAction(CAction::ACTION_CROUCH)->IsPerforming())
		return false;

	CCamera * pCam = m_pPlayer->GetCamera();
	oldFOV = pCam->GetFOV();
	oldMaxVelXZ = m_pPlayer->GetMaxVelocityXZ();
	//FOV is 120%
	pCam->SetFOV(oldFOV + (oldFOV / 5.0f));
	m_bCanPerform = false;
	m_bIsPerforming = true;
	//the player will be going 133% speed.
	m_pPlayer->SetMaxVelocityXZ(oldMaxVelXZ + (oldMaxVelXZ / 3.0f) );


	return true;
}

void CActionSprint::Complete()
{
	CCamera * pCam = m_pPlayer->GetCamera();
	pCam->SetFOV(oldFOV);
	m_pPlayer->SetMaxVelocityXZ(oldMaxVelXZ);
	m_bCanPerform = true;
	m_bIsPerforming = false;

}



CActionCrouch::CActionCrouch()
{
	m_bCanPerform   = true;
	m_bIsPerforming = false;


}


bool CActionCrouch::Perform(float param1, float param2, float param3, float param4)
{
	MikeUtils::ASSERT( (m_pPlayer && m_pPlayer->GetCamera() ), "Issue loading player/camera!", __FILE__, __LINE__);
	//Make the player short
	D3DXVECTOR3 newOffset = m_pPlayer->GetCamOffset();
	newOffset.y = (newOffset.y / 3.0f);
	m_pPlayer->SetCamOffset( newOffset );

	//If the player is sprinting, stop that.
	if(m_pPlayer->GetAction( CAction::ACTION_SPRINT )->IsPerforming() )
		m_pPlayer->CompleteAction(CAction::ACTION_SPRINT);

	//Slow the player's speed 
	m_pPlayer->SetMaxVelocityXZ(m_pPlayer->GetMaxVelocityXZ() / 2.0);

	m_bCanPerform = false;
	m_bIsPerforming = true;


	return true;
}

/*
bool CActionCrouch::CanPerform( )
{
	if(m_pPlayer->GetAction( CAction::ACTION_SPRINT )->IsPerforming() )
	{
		return false;
	}


} */

void CActionCrouch::Complete()
{

	MikeUtils::ASSERT( (m_pPlayer && m_pPlayer->GetCamera() ), "Issue loading player/camera!", __FILE__, __LINE__);
	D3DXVECTOR3 newOffset = m_pPlayer->GetCamOffset();
	newOffset.y = (newOffset.y * 3.0f);
	m_pPlayer->SetCamOffset( newOffset ); 

	//speed the player back up
	m_pPlayer->SetMaxVelocityXZ(m_pPlayer->GetMaxVelocityXZ() * 2.0);
	m_bCanPerform = true;
	m_bIsPerforming = false;

}
